<template>
    <div id="app">
        <transition>
            <navigation>
                <router-view @closeAll="toFirstPage"></router-view>
            </navigation>
        </transition>
    </div>
</template>
<script>
    export default {
        name: 'app',
        data() {
            return {
                routeList: []
            }
        },
        watch: {
            '$route'(route){
                let arrItem = {
                    name: route.name,
                    path: route.path
                };
                let preView = this.routeList[this.routeList.length - 2];
                if (preView && preView.name == arrItem.name && preView.path == arrItem.path) {
                    this.routeList = this.routeList.slice(0, this.routeList.length - 1);
                    if(arrItem.name != 'HomeIndex') {
                        localStorage.setItem("kfzxShowBackBtn", true);
                    }
                    return;
                }
                this.routeList.push(arrItem);
            }
        },
        methods: {
            toFirstPage(){
               this.$router.go(-(this.routeList.length-1));
               localStorage.setItem("kfzxShowBackBtn", false);
               this.routeList = [];
            }
        }
    };
</script>

<style lang="scss" type="text/scss">
    @import "./scss/variables";
</style>
